﻿@model List<Product>

@{
    ViewBag.Title = "title";
    Layout = "~/Views/_Layout.cshtml";
}




@using (Html.BeginForm("Delete","Product"))
{
    <table border="1">
        <thead>
            <tr>
                <th><input id="selectAll" name="selectAll" type="checkbox"/></th>
                <th>Urun Adı</th>
            </tr>
        </thead>
        <tbody>
            @Html.EditorForModel()
        </tbody>
    </table>
    
    <input  id="btnSubmit" type="submit" value="Seçilenleri Sil"/>
}

@section Scripts
{
 <script type="text/javascript">
    $(function () {
        $("#selectAll").click(function () {
            $("input[name='productIdsToDelete']").attr("checked", this.checked);
        });

        $("input[name='productIdsToDelete']").click(function () {
            if ($("input[name='productIdsToDelete']").lenght == $("input[name='productIdsToDelete']:checked")) {
                $("#selectAll").attr("checked", "checked");
            } else {
                $("#selectAll").removeAttr("checked");
            }
        });

        $("#btnSubmit").click(function () {
            var count = $("input[name='productIdsToDelete']:checked").length;

            if (count == 0) {
                alert("ürün seçiniz");
                return false;
            } else {
                return confirm(count + " ürün şeçili devam etmek istiyor musunuz?");
            }
        });

    });

</script>
}
